package com.wuxianedu.wechat.ui;

import com.wuxianedu.wechat.R;
import com.wuxianedu.wechat.base.BaseActivity;
import com.wuxianedu.wechat.util.Contants;
import com.wuxianedu.wechat.util.IntentHelper;
import com.wuxianedu.wechat.util.SharedPreferencesUtil;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class WelcomeActivity extends BaseActivity {

	private int what = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		boolean isLogin = SharedPreferencesUtil.getBoolean(context, Contants.IS_LOGIN);
		if(isLogin){
			handler.sendEmptyMessageDelayed(Contants.FORWARD_MAIN, 3000L);
			what = Contants.FORWARD_MAIN;
		}else{
			handler.sendEmptyMessageDelayed(Contants.FORWARD_LOGIN, 3000L);
			what = Contants.FORWARD_LOGIN;
		}
		
	}
	
	Handler handler = new Handler(){
		
		@Override
		public void handleMessage(Message msg) {
			if(msg.what == Contants.FORWARD_MAIN){
				IntentHelper.IntentToMain(context);
			}else{
				IntentHelper.IntentToLogin(context);
			}
			finish();
		}
		
	};
	
	protected void onDestroy() {
		super.onDestroy();
		handler.removeMessages(what);
	};
}
